apiready = function() {
    seajs.use(['../../V', "../../api", "../../jquery", "../../app", "../../service"], function(V, $api, $, $app, service) {
        var vm = {
            el: '#buy-publisth-comment',
            data: {
                submitInfo: {
                    unionid: '',
                    score: '', //--评论（2好评，1中评，0差评）
                    content: '', //--评价文字
                    images: '', //--评价图片
                    is_anony: '', //--是否匿名
                    star: '',
                    order_id: '',
                    goods_id: ''
                },
                goodsImg: '',
                is_group: true,
                imgLength: 0,
                imgList: [],
                list: '',
                describe: '', //--描述打分
                flow: '', //--物流打分
                attitude: '', //--态度打分
                name: ''
            },
            methods: {
                init: function() {

                },
                //--评价选择
                publishCommentSelect: function(et) {
                    var li = et.currentTarget.children;
                    var _li = et.target.tagName == "SPAN" ? et.target.parentNode : et.target;
                    for (var i = 0; i < li.length; i++) {
                        li[i].classList.remove("active");
                    }
                    _li.classList.add("active");
                    this.submitInfo.score = +_li.dataset.score;
                },
                //--店铺评分
                publishCommentScore: function(et) {
                    if (et.target.tagName == "DIV") {
                        return;
                    }
                    var span = et.currentTarget.children;
                    var index = +et.target.dataset.index;
                    for (var i = 0; i < span.length; i++) {
                        span[i].classList.remove("active");
                    }
                    for (var i = 0; i < index; i++) {
                        span[i].classList.add("active");
                    }
                    et.currentTarget.dataset.score = index;
                },
                //--提交评价
                publishCommentSubmit: function(et) {
                    var div = et.currentTarget;
                    var name = this.$refs.nameCheck
                    var self = this;
                    this.submitInfo.unionid = $api.getStorage("shop_unionid");
                    this.submitInfo.content = this.$refs.commentTxt.value || '';
                    this.submitInfo.is_anony = this.$refs.nameCheck.checked ? 1 : 0;

                    this.describe = this.$refs.describeScore.dataset.score;
                    this.flow = this.$refs.flowScore.dataset.score;
                    this.attitude = this.$refs.attitudeScore.dataset.score;
                    this.submitInfo.images = this.imgList.join(',');
                    if (this.submitInfo.score === '') {
                        $app.toast("请选择评价！");
                        return;
                    }
                    if (this.describe == "0") {
                        $app.toast("请为描述相符打分！")
                        return;
                    }
                    if (this.flow == "0") {
                        $app.toast("请为物流服务打分！")
                        return;
                    }
                    if (this.attitude == "0") {
                        $app.toast("请为服务态度打分！")
                        return;
                    }
                    this.submitInfo.star = this.describe + "|" + this.flow + "|" + this.attitude;
                    $app.ajax(service.buyOrderComment, {
                        data: {
                            values: self.submitInfo
                        }
                    }, function(res) {
                        //console.log("buyOrderComment: " + JSON.stringify(res));
                        if (res.code == 0) {
                            $app.openWin("buyCommentComplate", {
                                is_group: self.is_group,
                                order_id: self.submitInfo.sorder_id,
                                name: self.name
                            });
                        }
                    });
                },
                upLoadImg: function(et) {
                    var self = this;
                    if (this.imgLength >= 8) {
                        $app.toast("最多上传8张！");
                        return;
                    }
                    $app.getPictureS(8, this.imgLength, service['fileupload'], function(res) {
                        if (res.length > 0) {
                            self.imgLength = self.imgLength + res.length;
                            for (var i = 0; i < res.length; i++) {
                                self.imgList.push(res[i]);
                            }
                        } else {
                            api.toast({
                                msg: '图片上传失败，请重新上传',
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                    });
                },
                imgDelete: function(et) {
                    var index = +et.currentTarget.dataset.index;
                    this.imgList.splice(index, 1);
                    this.imgLength = this.imgLength - 1;
                }
            },
            mounted: function() {
                if (this.is_group) {
                    api.setStatusBarStyle({
                        style: 'light',
                        color: '#f42020'
                    });
                }
            },
            created: function() {
                this.is_group = api.pageParam.is_group;
                this.submitInfo.order_id = api.pageParam.order_id;
                this.submitInfo.goods_id = api.pageParam.goods_id;
                this.goodsImg = api.pageParam.goodsImg;
                this.name = api.pageParam.name;
                this.init();
            }
        };
        //var shopVue = new Vue(vm);
        var even = function() {

        };
        var newVue = new Vue(vm);
        even();

    })
}
